package com.anolesoft.amljmes.fortyone.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SQLUtil {
	public static void main1(String[] args) {
		String str1 = "insert into mes_stove_quality_customer\r\n" + 
				"  (objuid, mes_stove_base_uid, mes_stove_quailty_uid, seq_num, prorerty_name, prorerty_name_zn, prorerty_value, factory_id)\r\n" + 
				"values\r\n" + 
				"  (v_objuid, v_mes_stove_base_uid, v_mes_stove_quailty_uid, v_seq_num, v_prorerty_name, v_prorerty_name_zn, v_prorerty_value, v_factory_id);";
		String formatSQLmyBatis = formatSQLmyBatis(str1);
		System.out.println(formatSQLmyBatis);
	}
	
	public static void main(String[] args) {
		
		List<String> props = Arrays.asList(("pmd," + 
				"zxd," + 
				"ccd," + 
				"qxjmc," + 
				"sbbh," + 
				"qxwd," + 
				"gzfs," + 
				"gzwd," + 
				"gzsj," + 
				"cxdj," + 
				"ydzHrc," + 
				"ydzHra," + 
				"ydzHr15n," + 
				"ydzHb," + 
				"ydzHv," + 
				"jzqpmd," + 
				"jzqzxd," + 
				"jzhpmd," + 
				"jzhzxd," + 
				"jxxnlhsybgbh," + 
				"jxjclhsybgbh," + 
				"bmys," + 
				"dydstwd," + 
				"dydstsj," + 
				"dydstts," + 
				"dedstwd," + 
				"dedstsj," + 
				"dedstts," + 
				"dygsyqcsj," + 
				"dygsyschd," + 
				"degsyqcsj," + 
				"degsyschd," + 
				"dsgsyqcsj," + 
				"dsgsyschd," + 
				"llts," + 
				"clwd," + 
				"bmhhwd," + 
				"bmhhsj," + 
				"yyhwd," + 
				"yyhsj," + 
				"dydstjrwd," + 
				"dydstbwsj," + 
				"dydstafjl," + 
				"dedstjrwd," + 
				"dedstbwsj," + 
				"dedstafjl," + 
				"dsdstjrwd," + 
				"dsdstbwsj," + 
				"dsdstafjl," + 
				"qljzmc," + 
				"zkgzyl," + 
				"dydjrwd," + 
				"dydjrbwsj," + 
				"dedjrwd," + 
				"dedjrbwsj," + 
				"dsdjrwd," + 
				"dsdjrbwsj," + 
				"dsidjrwd," + 
				"dsidjrbwsj," + 
				"lqfs," + 
				"shuiwen," + 
				"youwen," + 
				"lpqtmc," + 
				"tqyq," + 
				"zysj," + 
				"sbbhdedjrbw," + 
				"sbbhdsdjrbw," + 
				"sbbhdsidjrbw").split(","));
	    List<String> zns = Arrays.asList(("平面度（mm）," + 
	    		"直线度（mm）," + 
	    		"粗糙度（um）," + 
	    		"清洗剂名称," + 
	    		"设备编号," + 
	    		"清洗温度," + 
	    		"干燥方式," + 
	    		"干燥温度（°c）," + 
	    		"干燥时间（min）," + 
	    		"脆性等级," + 
	    		"硬度值（hrc）," + 
	    		"硬度值（hra）," + 
	    		"硬度值（hr15n）," + 
	    		"硬度值（hb）," + 
	    		"硬度值（hv）," + 
	    		"校正前平面度（mm）," + 
	    		"校正前直线度（mm）," + 
	    		"校正后平面度（mm）," + 
	    		"校正后直线度（mm）," + 
	    		"机械性能理化实验报告编号," + 
	    		"金相检查理化实验报告编号," + 
	    		"表面颜色," + 
	    		"第一段渗碳温度（°c）," + 
	    		"第一段渗碳时间（min）," + 
	    		"第一段渗碳碳势（%）," + 
	    		"第二段渗碳温度（°c）," + 
	    		"第二段渗碳时间（min）," + 
	    		"第二段渗碳碳势（%）," + 
	    		"第一根试样（棒）取出时间（min）," + 
	    		"第一根试样（棒）渗层厚度（mm）," + 
	    		"第二根试样（棒）取出时间（min）," + 
	    		"第二根试样（棒）渗层厚度（mm）," + 
	    		"第三根试样（棒）取出时间（min）," + 
	    		"第三根试样（棒）渗层厚度（mm）," + 
	    		"炉冷碳势（%）," + 
	    		"出炉温度（°c）," + 
	    		"表面活化温度（°c）," + 
	    		"表面活化时间（min）," + 
	    		"预氧化温度（°c）," + 
	    		"预氧化时间（min）," + 
	    		"第一段渗氮加热温度（°c）," + 
	    		"第一段渗氮保温时间（min）," + 
	    		"第一段渗氮氨分解率（%）," + 
	    		"第二段渗氮加热温度（°c）," + 
	    		"第二段渗氮保温时间（min）," + 
	    		"第二段渗氮氨分解率（%）," + 
	    		"第三段渗氮加热温度（°c）," + 
	    		"第三段渗氮保温时间（min）," + 
	    		"第三段渗氮氨分解率（%）," + 
	    		"气冷介质名称," + 
	    		"真空工作压力（pa）," + 
	    		"第一段加热温度（°c）," + 
	    		"第一段加热保温时间（min）," + 
	    		"第二段加热温度（°c）," + 
	    		"第二段加热保温时间（min）," + 
	    		"第三段加热温度（°c）," + 
	    		"第三段加热保温时间（min）," + 
	    		"第四段加热温度（°c）," + 
	    		"第四段加热保温时间（min）," + 
	    		"冷却方式," + 
	    		"水温（°c）," + 
	    		"油温（°c）," + 
	    		"冷却气体名称," + 
	    		"通气压强（bar）," + 
	    		"转移时间（s）," + 
	    		"设备编号(第二段加热保温)," + 
	    		"设备编号(第三段加热保温)," + 
	    		"设备编号(第四段加热保温)").split(","));
		
		List<String> jsonStr = new ArrayList<>();
		List<String> jsonStr1 = new ArrayList<>();
		for (int i = 0; i < props.size(); i++) {
			String prop = props.get(i);
			String zn = zns.get(i);
			StringBuilder sb = new StringBuilder();
			sb.append("<a-col :span=\"8\" v-if=\"qualityShow."+prop+"Show\"><a-form-model-item label=\"").append(zn).append("\" :prop=\"").append("qualityShow."+prop+"Show.prop").append("\" ><a-input v-model=\"quality.").append(prop).append("\" placeholder=\"").append(zn).append("\" allowClear :style=\"qualityInputStyle\"></a-input></a-form-model-item></a-col>");
//			System.out.println(sb);
			
//			jsonStr.add(prop+": { required: true, message: '请填写"+zn+"', trigger: 'blur' }");
			
			jsonStr1.add("{value: \""+prop+"\", name: \""+zn+"\"}");
		}
		
//		System.out.println(jsonStr.stream().collect(Collectors.joining(",")));
		System.out.println(jsonStr1.stream().collect(Collectors.joining(",")));
	}

	private static String formatSQLmyBatis(String str) {
		String word = "v_";
		List<String> findWords = new ArrayList<>();
		int index = 0;
		while (true) {
			index = str.indexOf(word, index);
			int indexEnd = str.indexOf(",", index);
			if (indexEnd == -1) {
				indexEnd = str.indexOf(")", index);
				if (indexEnd == -1) {
					indexEnd = str.indexOf("\r\n", index);
				}
			}
			if (index == -1) {
				break;
			}

			String substring = str.substring(index, indexEnd);

			index = indexEnd;
			findWords.add(substring);
		}

		Map<String, String> collect = findWords.stream().distinct().collect(Collectors.toMap(w -> {
			return w;
		}, w -> {
			String w1 = w.replace(word, "");
			return "#{" + toCamelCase(w1) + "}";
		}));

		for (String key : collect.keySet()) {
			str = str.replaceAll(key, collect.get(key));
		}

		return str;
	}

	public static String toCamelCase(String underlineStr) {
		if (underlineStr == null) {
			return null;
		}
		// 分成数组
		char[] charArray = underlineStr.toCharArray();
		// 判断上次循环的字符是否是"_"
		boolean underlineBefore = false;
		StringBuffer buffer = new StringBuffer();
		for (int i = 0, l = charArray.length; i < l; i++) {
			// 判断当前字符是否是"_",如果跳出本次循环
			if (charArray[i] == 95) {
				underlineBefore = true;
			} else if (underlineBefore) {
				// 如果为true，代表上次的字符是"_",当前字符需要转成大写
				buffer.append(charArray[i] -= 32);
				underlineBefore = false;
			} else {
				// 不是"_"后的字符就直接追加
				buffer.append(charArray[i]);
			}
		}
		return buffer.toString();
	}
}
